package ma.strutsfacile.download;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.activation.FileTypeMap;
import javax.activation.MimetypesFileTypeMap;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class DownloadFileAction extends ActionSupport {

    private String name;
    private InputStream inputStream;
    private String contentType;
    private long size;
    private List radioList;
    private String radioListCheck;
    
    
    
    public String execute(){
	
	
	return SUCCESS;
	
    }
    
    public void prepare() throws Exception {
	System.out.println("prepare");
	radioList = new ArrayList();
	radioList.add("a1");
	radioList.add("a2");
        this.LOG.debug("prepare");
    }
    
    
    public List getRadioList() {
	
        return radioList;
    }
    public void setRadioList(List radioList) {
        this.radioList = radioList;
    }
    public String getRadioListCheck() {
        return radioListCheck;
    }
    public void setRadioListCheck(String radioListCheck) {
        this.radioListCheck = radioListCheck;
    }
    public String popFile() {
	try {
	    File file = new File("c:\\tour eifel.MOV");
	    this.inputStream = new FileInputStream(file);
	    this.name = file.getName();
	    this.size = file.length();
	    this.contentType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(file);
	} catch (FileNotFoundException e) {
	    return Action.ERROR;
	}
	if (inputStream != null) {
	    return Action.SUCCESS;
	} else {
	    // handle error
	    return Action.ERROR;
	}
    }
    public String downloadFile() {
	popFile();
	return Action.SUCCESS;
    }
    public InputStream getInputStream() {
	return inputStream;
    }
    public String getName() {
	return name;
    }
    public void setName(String name) {
	this.name = name;
    }
    public String getContentType() {
	return contentType;
    }
    public void setContentType(String contentType) {
	this.contentType = contentType;
    }

    public long getSize() {
	return size;
    }

    public void setSize(long size) {
	this.size = size;
    }
}
